﻿using System;
using Kernelx.Common.Threading;
using Microsoft.EntityFrameworkCore;


namespace Kernelx.Contexts
{
    /// <summary>
    /// 
    /// </summary>
    public static class ServiceProviderExtensions
    {

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TContext"></typeparam>
        /// <param name="provider"></param>
        public static void SetCurrentDbContext<TContext>(this IServiceProvider provider) where TContext : DbContext
            => CurrentDbContext.Set(typeof(TContext));
        internal static ConcurrentContainer<Type> CurrentDbContext = new ConcurrentContainer<Type>();

         
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TContext"></typeparam>
        /// <param name="provider"></param>
        public static void SetCurrentSlaveDbContext<TContext>(this IServiceProvider provider) where TContext : DbContext,ISlaveDbContext
            => CurrentSlaveDbContext.Set(typeof(TContext));
        internal static ConcurrentContainer<Type> CurrentSlaveDbContext = new ConcurrentContainer<Type>();

         
    }
}
